package com.atguigu.edu.realtime.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {
    
    private static JedisPool pool;
    
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(300);
        config.setMaxIdle(10);
        config.setMinIdle(5);
        config.setMaxWaitMillis(10 * 1000);
        config.setTestOnCreate(true);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        pool = new JedisPool(config, "hadoop162", 6379);
    }
    public static Jedis getRedisClient() {
        Jedis jedis = pool.getResource();
        jedis.select(4);// 选择 4 号库
        // 获取连接客户端
        return jedis;
    }
}
